<template>
    <!-- pages/myset/index.wxml -->
    <!-- <view class="page">
  <view class="flexbox">
    <view class="navs">
      <view>
        <image src="{{imgUrl + 'set1.png'}}"></image>
        新消息通知
      </view>
      <van-switch active-color="#FF8722" checked="{{ checked }}" bind:change="onChange" />
    </view>
    <navigator url="../setphone/index" hover-class="navigator-hover">
      <view class="navs">
        <view>
          <image src="{{imgUrl + 'set2.png'}}"></image>
          修改手机号码
        </view>
        <view>
          {{mobile}}
          <image  class="icon-32" src="{{imgUrl + 'right.png'}}"></image>
        </view>
      </view>
    </navigator>
    <navigator url="../setpassword/index" hover-class="navigator-hover">
      <view class="navs">
        <view>
          <image src="{{imgUrl + 'set3.png'}}"></image>
          修改密码
        </view>
        <view>

          <image  class="icon-32" src="{{imgUrl + 'right.png'}}"></image>
        </view>
      </view>
    </navigator>
  </view>
  <view class="flexbox flexbox1">
    <navigator wx:for="{{menu}}" wx:key="Index" url="{{item.url}}" class="navs" bindtap="{{item.incident}}">
      <view>
        <image src="{{item.img}}" class="nor {{item.className}}" />
        {{item.name}}
      </view>
      <view>
        <text wx:if="{{item.name == '微信账号'}}">{{findObj.wxToken ? item.text1 : item.text}}</text>
        <text wx:elif="{{item.name == '实名认证'}}">
          <text wx:if="{{userStatus == 3}}">未实名</text>
          <text wx:if="{{userStatus == 0}}">审核中</text>
          <text wx:if="{{userStatus == 1}}">已实名</text>
        </text>

        <text wx:else>{{item.text}}</text>
        <image  class="icon-32" src="{{imgUrl + 'right.png'}}"></image>
      </view>

    </navigator>
  </view>
  <view class="outbtn" bindtap="onOut">
    退出登录
  </view>
</view>
<van-share-sheet show="{{ showShare }}" title="立即分享" options="{{ options }}" bind:select="onSelect"
  bind:close="onClose" /> -->

    <view class="page">
        <view class="flexbox">
            <!-- <navigator url="../auth/index" hover-class="navigator-hover">
      <view class="navs">
        <view>
          <image src="{{imgUrl + 'set5.png'}}"></image>
          用户信息
        </view>
        <view>
          <image  class="icon-32" src="{{imgUrl + 'right.png'}}"></image>
        </view>
      </view>
    </navigator> -->
            <!-- <text wx:if="{{userStatus == 3}}">未实名</text> -->
            <!-- <text wx:if="{{userStatus == 0}}">审核中</text>
          <text wx:if="{{userStatus == 1}}">已实名</text> -->
            <navigator url="/pages/myset/resetpassword/index" hover-class="navigator-hover">
                <view class="navs">
                    <view>
                        <image class="icon-24-32" :src="imgUrl + 'setpaypassword-icon.png'"></image>
                        修改登录密码
                    </view>
                    <view>
                        <image class="icon-32" :src="imgUrl + 'right.png'"></image>
                    </view>
                </view>
            </navigator>
            <navigator url="../setphone/index" hover-class="navigator-hover">
                <view class="navs">
                    <view>
                        <image class="icon-28-36" :src="imgUrl + 'setphone-icon.png'"></image>
                        修改手机号码
                    </view>
                    <view>
                        {{ mobile }}
                        <image class="icon-32" :src="imgUrl + 'right.png'"></image>
                    </view>
                </view>
            </navigator>
            <navigator v-if="bool" url="../myset/setpaymentcode/index" hover-class="navigator-hover">
                <view class="navs">
                    <view>
                        <image class="icon-32-36" :src="imgUrl + 'paypassword-icon.png'"></image>
                        支付密码
                    </view>
                    <view>
                        <image class="icon-32" :src="imgUrl + 'right.png'"></image>
                    </view>
                </view>
            </navigator>
            <navigator v-if="!bool" url="../../pages/setpaypassword/index" hover-class="navigator-hover">
                <view class="navs">
                    <view>
                        <image class="icon-32-36" :src="imgUrl + 'paypassword-icon.png'"></image>
                        支付密码
                    </view>
                    <view>
                        <image class="icon-32" :src="imgUrl + 'right.png'"></image>
                    </view>
                </view>
            </navigator>
            <navigator url="/pages/wallet/bankcardmanagement/index" hover-class="navigator-hover">
                <view class="navs">
                    <view>
                        <image class="icon-32" :src="imgUrl + 'management-icon.png'"></image>
                        提现账户管理（含实名认证）
                    </view>
                    <view>
                        <image class="icon-32" :src="imgUrl + 'right.png'"></image>
                    </view>
                </view>
            </navigator>
        </view>
        <view class="outbtn" @tap="onOut">
            {{ bntName }}
        </view>
    </view>
</template>

<script>
import tabbar from '../../component/tabbar/index';
// pages/myset/index.js
const app = getApp(); // 引入app

import _request from '../../utils/request.js';
export default {
    components: {
        tabbar
    },
    data() {
        return {
            checked: true,
            imgUrl: app.globalData.imgUrl,

            //全局img路径
            menu: [
                {
                    name: '微信账号',
                    url: '../setpassword/index',
                    img: 'https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set4.png',
                    text: '未绑定',
                    text1: '已绑定',
                    text2: '审核中'
                },
                {
                    name: '实名认证',
                    url: '../myset/realname/index',
                    img: 'https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set5.png',
                    text: '未实名',
                    text1: '已实名'
                },
                {
                    name: '提现账户管理',
                    url: '../setpassword/index',
                    img: 'https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set6.png',
                    text: ''
                },
                {
                    name: '支付密码',
                    url: '../payfail/index',
                    img: 'https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set7.png',
                    text: ''
                },
                {
                    name: '清理缓存',
                    url: '../setpassword/index',
                    img: 'https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set8.png',
                    text: '500MB'
                },
                {
                    name: '分享意约',
                    url: '',
                    img: 'https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set9.png',
                    text: '',
                    incident: 'onClick',
                    userStatus: ''
                }
            ],

            showShare: false,

            options: [
                {
                    name: '微信',
                    icon: 'wechat',
                    openType: 'share'
                },
                {
                    name: '微博',
                    icon: 'weibo'
                },
                {
                    name: '复制链接',
                    icon: 'link'
                },
                {
                    name: '分享海报',
                    icon: 'poster'
                },
                {
                    name: '二维码',
                    icon: 'qrcode'
                }
            ],

            findObj: null,
            mobile: '',
            bntName: '退出登录',
            userStatus: 0,
            bool: false
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (!uni.getStorageSync('token')) {
            this.setData({
                bntName: '账号密码登录'
            });
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        // 账户信息
        _request
            .get('/settings/accountSafe/find', {
                userId: uni.getStorageSync('userid')
            })
            .then((res) => {
                this.setData({
                    findObj: res.data.data,
                    mobile: this.formatPhone(res.data.data.mobile)
                });
            })
            .catch((error) => {
                console.log(error, 'error');
            }); // 实名状态

        _request
            .get('/storeAuthApply/getStoreAuthApplyByStoreId', {
                storeId: uni.getStorageSync('storeId')
            })
            .then((res) => {
                if (res.data.data == '暂未申请认证信息') {
                    this.setData({
                        userStatus: 3
                    });
                }

                this.setData({
                    userStatus: res.data.data.status
                });
            })
            .catch((error) => {
                console.log(error, 'error');
            }); // /userAuthApply/getApplyStatus
        // 是否设置密码

        _request
            .get('/settings/initPayWord', {
                userId: uni.getStorageSync('userid')
            })
            .then((res) => {
                if (res.data.message == '支付密码还未设置' && res.data.data == 0) {
                    this.setData({
                        bool: false
                    });
                } else {
                    this.setData({
                        bool: true
                    });
                }
            });
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        // 分享操作
        onClick(event) {
            this.setData({
                showShare: true
            });
        },

        onClose() {
            this.setData({
                showShare: false
            });
        },

        onSelect(event) {
            Toast(event.detail.name);
            this.onClose();
        },

        // 需要手动对 checked 状态进行更新
        onChange({ detail }) {
            this.setData({
                checked: detail
            });
        },

        // 退出登录/登录
        onOut() {
            //登录
            if (!uni.getStorageSync('token')) {
                uni.navigateTo({
                    url: '/pages/login/index'
                });
                return;
            }

            app.globalData.closeTcp(); //获取code, 退出登录

            uni.login({
                success: (res) => {
                    // 获取到用户的 code 之后：res.code}
                    let code = res.code; // 账户信息

                    _request
                        .postObj('/settings/unBindWX', {
                            userId: uni.getStorageSync('userid'),
                            code
                        })
                        .then((res) => {
                            if (res.data.code == 200) {
                                uni.clearStorage();
                                uni.reLaunch({
                                    //清除所有的历史页面
                                    // url: '/firstpages/my/index',
                                    url: '/pages/login/index'
                                });
                            } else if (res.data.message == '该帐号暂时没有微信绑定') {
                                uni.clearStorage();
                                uni.reLaunch({
                                    // url: '/firstpages/my/index',
                                    url: '/pages/login/index'
                                });
                            }
                        })
                        .catch((error) => {
                            console.log(error, 'error');
                        });
                }
            });
        },

        formatPhone(phone) {
            return phone.substr(0, 3) + '****' + phone.substr(7, 11);
        }
    }
};
</script>
<style>
/* pages/myset/index.wxss */
page {
    background: #fbfbfb;
    position: relative;
}

.page {
    margin-bottom: 236rpx;
}

/* 第一个设置栏 */
.flexbox {
    margin: 0 20rpx;
    margin-top: 20rpx;
    width: 710rpx;
    /* height: 312rpx; */
    background: #ffffff;
    box-shadow: 1px 1px 4px 1px rgba(241, 241, 241, 0.4);
    border-radius: 5px;
}

.navs {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    height: 104rpx;
    border-bottom: 1px solid #e5e5e5;
    justify-content: space-between;
    padding: 0 20rpx;
}

.navs > view {
    height: 100%;
    display: flex;
    align-items: center;
}

.flexbox image {
    margin-right: 10rpx;
}

.navs > view:nth-child(2) {
    font-size: 28rpx;
    font-family: PingFangSC-Light, PingFang SC;
    font-weight: 300;
    color: #999999;
}
/* 第二个设置栏 */
.flexbox1 {
    height: 100%;
}

/* 退出按钮 */

.outbtn {
    width: 710rpx;
    height: 84rpx;
    background: #ebebeb;
    border-radius: 42rpx;
    margin: 0 20rpx;
    text-align: center;
    line-height: 84rpx;
    margin-top: 106rpx;
    font-size: 32rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
}

.icon-24-32 {
    width: 24rpx;
    height: 32rpx;
}

.icon-28-36 {
    width: 28rpx;
    height: 36rpx;
}

.icon-32-36 {
    width: 32rpx;
    height: 36rpx;
}
</style>
